<?php
namespace app\home\controller;

use \app\home\model\Category as CatModel;
use \app\home\model\Article as ArtModel;
use \think\Validate as Validate;
class Cat extends Home{
    public function index(){
        return $this->fetch();
    }
    public function hand(){
        $cat_id = $this->req->get('id','int');
        if(isset($cat_id)){
            $model = new CatModel;
            $cat = $model->where('cat_id',$cat_id)->find();
            $model = new ArtModel;
            $docs = $model->where('art_cat_id',$cat_id)->select();
            if(empty($cat) || empty($docs)){
                echo "<script>alert('没有文章')</script>";
//                echo json_encode(['error_msg'=>'1']);
            }else{
                $this->assign(['cat'=>$cat,'docs'=>$docs]);
//                echo json_encode($cat);
                return $this->fetch();
            }
        }else{
            $this->error('致命错误');
        }
    }

    /**
     * 获取文章内容。
     */
    public function post(){
        $id = $this->req->param('id','int');
        if(isset($id)){
            $model = new ArtModel;
            $data = $model->where('art_id',$id)->find();
            if(empty($article)){
                $this->assign('data',$data);
                echo  $this->fetch();

            }else{
                echo "<h2>无数据</h2>";
                
            }
            
        }else{
            echo "<h2>数据错误</h2>";
        }
    }

    public function thinkphp(){
        
    }

    /**
     * 添加留言！
     */
    public function addmsg(){
        $data = $this->req->post();
        $rules = [
            'id' => 'require',
            'content' => 'require'
        ];
        $message = [
            'id.require' => 'id不能为空',
            'content.require' => '内容不能为空'
        ];

        $validate = new Validate($rules,$message);
        $result = $validate->check($data);
        if($result){
            $
        }else{
            return 
        }
                 
               
    }
}
